#region Using
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using CY.GFive.Core.Business;
using CY.Utility.DBUtility;
#endregion Using

namespace CY.GFive.DALProviders.SqlServerProvider
{
	public class JuryArrangeProvider : CY.GFive.Core.Providers.DALProvider.IJuryArrangeProvider
	{
		#region Sql
		private static readonly string SqlSelectJuryArrange = "SELECT [Id]  FROM [JuryArrange] WHERE  [Id]=@Id";

		private static readonly string SqlInsertJuryArrange = "INSERT INTO [JuryArrange]() values();SELECT SCOPE_IDENTITY();";

		private static readonly string SqlUpdateJuryArrange = "UPDATE [JuryArrange] SET  WHERE  [Id]=@Id";

		private static readonly string SqlDeleteJuryArrange = "DELETE [JuryArrange] WHERE  [Id]=@Id";

		private static readonly string SqlGetAllJuryArrange = "SELECT [Id]  FROM [JuryArrange]";
		#endregion

		#region IJuryArrangeProvider Members
		public Core.Business.JuryArrange Select(int id)
		{
			SqlServerUtility sql = new SqlServerUtility();

			sql.AddParameter("@Id", SqlDbType.Int, id);
			SqlDataReader reader = sql.ExecuteSqlReader(SqlSelectJuryArrange);

			if (reader != null && !reader.IsClosed && reader.Read())
			{
				Core.Business.JuryArrange juryArrange = new Core.Business.JuryArrange();

				if (!reader.IsDBNull(0)) juryArrange.Id = reader.GetInt32(0);

				return juryArrange;
			}
			else
			{
				if (reader != null && !reader.IsClosed)
					reader.Close();

				return null;
			}
		}

		public void Insert(Core.Business.JuryArrange juryArrange)
		{
			SqlServerUtility sql = new SqlServerUtility();

			SqlDataReader reader = sql.ExecuteSqlReader(SqlInsertJuryArrange);

			if (reader != null && !reader.IsClosed && reader.Read())
			{
				if (!reader.IsDBNull(0)) juryArrange.Id = int.Parse(reader.GetDecimal(0).ToString());

				reader.Close();
			}
			else
			{
				if (reader != null && !reader.IsClosed)
					reader.Close();
			}
		}

		public void Update(Core.Business.JuryArrange juryArrange)
		{
			SqlServerUtility sql = new SqlServerUtility();

			sql.AddParameter("@Id", SqlDbType.Int, juryArrange.Id);
			sql.ExecuteSql(SqlUpdateJuryArrange);
		}

		public void Delete(Core.Business.JuryArrange juryArrange)
		{
			SqlServerUtility sql = new SqlServerUtility();

			sql.AddParameter("@Id", SqlDbType.Int, juryArrange.Id);
			sql.ExecuteSql(SqlDeleteJuryArrange);
		}

		public IList<Core.Business.JuryArrange> GetAllJuryArrange()
		{
			IList<Core.Business.JuryArrange> juryArrangelist = new List<Core.Business.JuryArrange>();
			SqlServerUtility sql = new SqlServerUtility();

			SqlDataReader reader = sql.ExecuteSqlReader(SqlGetAllJuryArrange);

			if(reader != null)
			{
				while(reader.Read())
				{
					Core.Business.JuryArrange juryArrange = new Core.Business.JuryArrange();

					if (!reader.IsDBNull(0)) juryArrange.Id = reader.GetInt32(0);

					juryArrange.MarkOld();
					juryArrangelist.Add(juryArrange);
				}
				reader.Close();
			}
			return juryArrangelist;
		}
		#endregion
	}
}
